<template>
  <div>
    <a-card :bordered="false">
      <div class="table-page-search-wrapper">
        <a-form layout="inline" @keyup.enter.native="searchList">
          <a-row :gutter="48">
            <a-col :md="8" :sm="24">
              <a-form-item label="搜索">
                <a-input v-model="queryParam.search" />
              </a-form-item>
            </a-col>
            <a-col :md="8" :sm="24">
              <a-form-item label="盒子类型">
                <a-select v-model="queryParam.type" placeholder="请选择" :getPopupContainer="triggerNode => triggerNode.parentNode">
                  <a-select-option value="">不限</a-select-option>
                  <a-select-option value="10">搭配师</a-select-option>
                  <a-select-option value="20">导购</a-select-option>
                  <!-- <a-select-option :value="item.value" v-for="(item, index) in advertLoc" :key="index">{{ item.text }}</a-select-option> -->
                </a-select>
              </a-form-item>
            </a-col>
            <a-col :md="8" :sm="24">
              <a-form-item label="发货状态">
                <a-select v-model="queryParam.status" placeholder="请选择" :getPopupContainer="triggerNode => triggerNode.parentNode">
                  <a-select-option value="">不限</a-select-option>
                  <a-select-option :value="0">未发货</a-select-option>
                  <a-select-option :value="1">已发货</a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
            <a-col :md="24" :sm="24">
              <span class="table-page-search-submitButtons" :style="{ float: 'right', overflow: 'hidden' }">
                <a-button type="primary" @click="searchList">查询</a-button>
                <a-button style="margin-left: 18px" @click="resetList">重置</a-button>
              </span>
            </a-col>
          </a-row>
        </a-form>
      </div>
      <s-table ref="table" size="default" :rowKey="record => record.id" :columns="columns" :data="loadData" :pagination="paginationProps" :scroll="{ x: 1200 }">
        <span slot="type" slot-scope="text">
          {{ text | type }}
        </span>
        <span slot="action" slot-scope="text, record">
          <a-popconfirm title="确定结案吗?" ok-text="Yes" cancel-text="No" @confirm="handleEdit(record)" v-if="record.status != 1">
            <a href="#">结案</a>
          </a-popconfirm>
        </span>
      </s-table>
    </a-card>
  </div>
</template>
<script>
import { ebOrderList, closeEbOrder } from '@/api/box/setting'
import { listMixin } from '@/views/box/util/listMixin'
let columns = [
  {
    title: '服务单号',
    dataIndex: 'boxSn'
  },
  {
    title: '发货单号',
    dataIndex: 'ebTransfersumDocno'
  },
  {
    title: '盒子类型',
    dataIndex: 'type',
    width: 90,
    scopedSlots: { customRender: 'type' }
  },
  {
    title: '所属搭配师',
    dataIndex: 'fashionerName',
    width: 130
  },
  {
    title: '会员手机号',
    dataIndex: 'cusPhone',
    width: 130
  },
  {
    title: '内淘发货门店',
    dataIndex: 'sendStoreName'
  },
  {
    title: '内淘数量',
    dataIndex: 'qty',
    width: 90
  },
  {
    title: '创建时间',
    dataIndex: 'createTime'
  },
  {
    title: '发货状态',
    dataIndex: 'status',
    width: 90,
    customRender: text => (text == 1 ? '已发货' : '未发货')
  },
  {
    title: '操作',
    fixed: 'right',
    width: 70,
    scopedSlots: { customRender: 'action' }
  }
]
export default {
  mixins: [listMixin],
  data() {
    return {
      columns,
      queryParam: {
        status: '',
        type: ''
      },
      loadData: parameter => this.fetchData(parameter)
    }
  },
  filters: {
    type(t) {
      if (t == 10) {
        return '搭配师'
      }
      if (t == 20) {
        return '导购'
      }
    }
  },
  methods: {
    fetchData(parameter) {
      let params = {
        page: parameter,
        requestData: this.queryParam
      }
      try {
        return this.fetchList(params, ebOrderList).then(res => {
          if (res.code == 0) {
            return {
              page: res.page,
              data: res.data
            }
          } else {
            this.$message.warning(res.msg)
            return {
              data: [],
              page: {
                pageNo: 1,
                pageSize: 10,
                count: 0
              }
            }
          }
        })
      } catch (err) {
        console.log(err)
      }
    },
    resetList() {
      this.queryParam = {
        status: '',
        type: ''
      }
      this.$refs.table.refresh(true)
    },
    handleEdit(record) {
      closeEbOrder(record.id).then(res => {
        if (res.code == 0) {
          this.$message.success('结案成功')
          this.$refs.table.refresh()
        } else {
          this.$message.success(res.msg)
        }
      })
    }
  }
}
</script>

